package com.travel.controller;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.travel.bean.OrderModel;
import com.travel.bean.State;
import com.travel.service.OrderService;
import com.travel.service.StateService;
import com.travel.utils.PageHelper;

@Controller
@RequestMapping("/order")
public class OrderController {
	/**
	 * 订单业务的实现注入
	 */
	@Resource(name="orderServiceImpl")
	private OrderService orderService;
	/**
	 *订单状态业务的实现注入
	 */
	@Resource(name="stateServiceImpl")
	private StateService stateService;
	/**
	 * 跳转到订单预定界面
	 * @return
	 */
	@RequestMapping("/toorder.html")
	public String toOrder(Integer routeId ,Integer childNum,Integer mamNum, Date date ,Map map){
		map.put("routeId", routeId);
		map.put("childNum",childNum );
		map.put("mamNum",mamNum );
		map.put("date",date );
		return "jsp/toorder";
	}
	
	/**
	 * 用户下订单
	 */
	@RequestMapping("/order.do")
	public String orderDo(OrderModel orders,Map map){
		boolean flag=orderService.addOrders(orders.getOrders(),7);
		
		if(flag){
			return "redirect:/comm/index.html";
		}
		return "jsp/order";
	}
	
	/**
	 * 管理员查看所有订单
	 */
	@RequestMapping("tovieworder.html")
	public String toViewOrder(Map map){
		Collection<State> states=stateService.queryEntry();
		map.put("states", states);
		return "admin/vieworder";
	}
	/**
	 * 异步加载所有的订单展示项
	 * @return
	 */
	@RequestMapping("/vieworder.do")
	@ResponseBody
	public Map viewOrder(Integer page,Integer limit){
		Map map=new HashMap();
		PageHelper pages=orderService.getPageByMap(null, page, limit);
		map.put("code",0);
		map.put("msg", "订单详情");
		map.put("count",pages.getTotalPageCount());
		map.put("data", pages.getList());
		return map;
	}
	
}
